import DWC_ListViewCtrl from "./DWC_ListViewCtrl";
import {GCtrl} from "../../lib/util/GCtrl";
import FPJDefine from "../../Game/FPJ/Prefabs/FPJDefine";
import BaseComponent from "../../Game/Base/BaseClass/BaseComponent";


const {ccclass, property} = cc._decorator;

@ccclass
export default class FPJ_FriendList extends BaseComponent {


    @property(cc.EditBox)
    editBox: cc.EditBox = null;

    @property(DWC_ListViewCtrl)
    FPJ_ListViewCtrlCom:DWC_ListViewCtrl = null;

    //玩家列表信息数据
    _data = null;

    start () {

    }

    init(){
        this.initData();
    }
    initData(){
        //玩家列表数据
        this.clearSelf();
        this.initUI();
    }

    clearSelf(){
        this._data = [];
        for(let i in FPJDefine.player_list ){
            let dataItem = FPJDefine.player_list[i];
            if(dataItem["rid"] == cc.vv.session.getRid() ){

            }else {
                this._data.push(JSON.parse( JSON.stringify(dataItem) ) );
            }
        }
    }

    //编辑中
    textChange(){
        this.initUI();
    }

    initUI(){
        this.serchData();
    }

    /**
     * 这里处理模糊查询数据
     * this._data是原数据
     * 根据输入的目标
     * 将得出一份searchData
     */
    serchData(){
        //输入目标
        let searchTarget = this.editBox.string;
        //模糊数据
        let searchData = [];
        //开始处理数据
        if(searchTarget.length == 0){
            searchData = this._data;
        }else {

            for(let i in this._data ){
                let dataItem = this._data[i];
                if( dataItem["rolename"].search(searchTarget) !== -1 ){
                    searchData.push(dataItem);
                }
            }
        }
        this.initListView(searchData);
    }

    initListView(searchData){
        this.FPJ_ListViewCtrlCom.initData(searchData,this);
    }

    btnClickClose(){
        GCtrl.UIMgr.close(GCtrl.GLConfig.DWC_FriendList_path, GCtrl.UIMgr.closeType.hide);
        cc.vv.audioUtil.playSound("/Hall/sound/button_onclicked");
    }

}
